

<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>注册</title>
		<link type="text/css" rel="styleSheet" href="__CDN__/assets/css/register.css" />
		<script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script src="__CDN__/assets/js/md5.js"></script>
	</head>

	<body>
		<div class="container">
			<div class="title">
				邀请注册
			</div>
			<div class="input-container">
				<div class="item">
					<input type="text" id="phone" value="" placeholder="请输入手机号" />
				</div>
				<div class="item">
					<input type="number" style="width:60%" maxlength="6" id="code" value="" placeholder="请输入验证码" />
					<div id="get_code" class="code">获取验证码</div>
				</div>
				<div class="item">
					<input type="password" id="password" value="" placeholder="请输入密码" />
				</div>
				<div class="item" style="margin-bottom:20px">
					<input style="color:#fff" type="text" id="tuijian" value="{$invite_code}" placeholder="请输入推荐人" />
				</div>
				<div class="item" style="border:0;margin-bottom:15px;">
					<input type="button" id="btn"  value="立即注册" style="padding:0;height:50px;background: #FB6171;border-radius: 25px;font-size: 16px;color:#fff" />
				</div>
				<div class="item" style="border:0">
					<input type="button" id="down" value="已注册？可直接下载app" style="padding:0;height:50px;background: #FB6171;border-radius: 25px;font-size: 16px;color:#fff" />
				</div>
			</div>
			<div class="header">
				<img src="__CDN__/assets/img/logo.png" style="width: 45px;height: 45px;" />
			</div>
		</div>
		<div id="showtoast" class="showtoast">
			<div id="msg" class="msg"></div>
		</div>
		<script>
			var android = "{$version.android}";
			var ios = "{$version.ios}";

			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]);
				return null;
			}
			function showtoast(obj) {
				$('#showtoast').css('display', 'flex')
				$('#msg').html(obj.msg)
				var time = obj.dur ? obj.dur : 1500
				setTimeout(() => {
					$('#showtoast').css('display', 'none')
					$('#msg').html('')
				}, time)
			}
			
			function downapp(){
				var u = navigator.userAgent;
					var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
					var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
					if (isAndroid&&android) {
						window.location.href = android;
					}
					if (isiOS&&ios) {
						window.location.href = ios;
					
					}
			}
			
			var time1 = '';
			var second = 60;
			var host = "http://www.ipst.xyz/api/"
			$(function() {
				// var pusername = getQueryString('pusername')
				// if (pusername) {
				// 	var newval=pusername.split(".");
				// 	$('#tuijian').val(newval[0])
				// 	$('#tuijian').attr('disabled', 'disabled')
				// }
				$('#biyan').click(function() {
					$('#biyan').css({"display":"none"})
					$('#zhengyan').css({"display":"block"})
					$('#password').attr('type','text')
				})
				$('#zhengyan').click(function() {
					$('#zhengyan').css({"display":"none"})
					$('#biyan').css({"display":"block"})
					$('#password').attr('type','password')
				})
				$('#get_code').click(function() {
					var str = $('#get_code').html()
					if (str == '获取验证码' || str == '重新获取') {
						var phone = $('#phone').val()
						if (!phone) {
							showtoast({
								msg: '请输入手机号码'
							})
							return;
						}
						if (!(/^1[3456789]\d{9}$/.test(phone))) {
							showtoast({
								msg: '手机格式不正确'
							})
							return;
						}
						$('#get_code').html(second + 's 重新获取')
						time1 = setInterval(() => {
							second--;
							$('#get_code').html(second + 's 重新获取')
							if (second < 0) {
								$('#get_code').html('重新获取')
								clearInterval(time1)
							}
						}, 1000);
						
						
						$.ajax({
							type: "POST",
							url: host + "user/code/send",
							data: {
								mobile: phone,
							},
							dataType: "json",
							success: function(data) {
								if (data.code) {
									showtoast({
										msg: data.msg
									})
									
									
								} else {
									showtoast({
										msg: data.msg
									})
								}
							},
							fail: function(res) {
								showtoast({
									msg: res.msg
								})
							}
						});
						
					} else {
						var obj = {
							msg: second + '后再重新获取',
							icon: 'none',
							dur: 1500,
						}
						showtoast(obj)
					}
				})
				$('#btn').click(function() {
					var phone = $('#phone').val()
					var password = $('#password').val()
					var code = $('#code').val()
					var tuijian = $('#tuijian').val()
					if (!phone) {
						showtoast({
							msg: '请输入手机号码'
						})
						return;
					}
					if (!(/^1[34578]\d{9}$/.test(phone))) {
						showtoast({
							msg: '手机格式不正确'
						})
						return;
					}
					if (!code || code.length < 6) {
						showtoast({
							msg: '请输入6位验证码'
						})
						return;
					}
					if (!password) {
						showtoast({
							msg: '请输入密码'
						})
						return;
					}
					if (!tuijian) {
						showtoast({
							msg: '请输入推荐人号码'
						})
						return;
					}
					$.ajax({
						type: "POST",
						url: host + "user/public/register",
						data: {
							mobile: phone,
							invite_code: tuijian,
							verification_code: code,
							password: password,
							confirm_password:password
						},
						dataType: "json",
						success: function(res) {
							if (res.code) {
								showtoast({
									msg: '注册成功，自动跳转到下载页'
								})
								downapp()
							} else {
								showtoast({
									msg: res.msg
								})
							}
						},
						fail: function(res) {
							showtoast({
								msg: res.msg
							})
						}
					});
				})
				$('#down').click(function() {
					downapp()
				})
			})
		</script>
	</body>

</html>
